package  wibrst.utils{
	import flash.display.DisplayObject;
	import flash.net.LocalConnection;
	import flash.text.TextField;
	import flash.utils.getQualifiedClassName;
	import flash.utils.getQualifiedSuperclassName;
	/**
	 * ...
	 * @author wibrst@qq.com
	 */
	public class DevUtil {
		
		static public function gc():void {
			if ( LocalConnection.isSupported ) {
				try{
					var sConflict:String = "trigger a gc";
					var lc1:LocalConnection = new LocalConnection;
					lc1.connect( sConflict );
					var lc2:LocalConnection = new LocalConnection;
					lc2.connect ( sConflict ) ;
				}catch ( err :Error ) {
					
				}
			}else {
				trace( "[DevUtil] LocalConnection.isSupported false !!!" );
			}
		}
		
		static public function parseUpMysticalVisual( disp:DisplayObject ):String {
			var sTrac:String = "--- --- --- parseMysticalVisual:";
			while ( disp ) {
				sTrac += "\n\t" + disp + " n:" + disp.name + " a:" + disp.alpha + " v:" + disp.visible + " x:" + disp.x + " y:" + disp.y + " w:" + disp.width + " h:" + disp.height;
				disp = disp.parent;
			}
			return sTrac;
		}
		
		static public function viewObj( obj:Object ):String {
			return	"!!! viewObj:" + obj
				+"\n\tclass:"+ getQualifiedClassName( obj )
				+"\n\tsuper class:"+ getQualifiedSuperclassName( obj ) ;
		}
		
		static public function viewThru(tgt:*, bBrief:Boolean = false, nLevel:Number = 1, nLevelRestrict:Number = 8, bHtmlMode:Boolean = false, userMsg:String = "" ):String {
			if( !tgt ) return "";
			
			var bHasProps:Boolean = false;
			var msg:String = "";
			if (nLevel == 1) {
				msg += bHtmlMode ?
					"<br>┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯<br>"		// <font color='#666666'>" + tgt + "</font> " + typeof (tgt) + "<br>"
					:"\n┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯\n";				// + tgt + " " + typeof (tgt) + "\n";
				userMsg != "" ? msg += userMsg+"<br>" : null;
			}
			
			for (var x:String in tgt) {
				bHasProps = true;
				var elmt:* = tgt[x];
				var type:String = typeof (elmt);
				var valueElement:String = ( elmt!=null )
						? ( bHtmlMode
								? " <font color='#666666'>" + elmt + "</font>" + " " + type
								: elmt + " (" + type +")"  /*+String(elmt is Object)*/ )
						 : ( bHtmlMode
								? " &lt;未定义&gt;"
								: "<未定义>" );
				var sValueBrief:String = bBrief ? StringUtil.getBrief( valueElement.toString() as String, 24, 20, 10, false ) : valueElement;
				var add_str:String = bHtmlMode
						? " <b>" + x + "</b> :" + sValueBrief
						: " " + x + " :" + sValueBrief;
				
				msg += getIndent(nLevel) + add_str + (bHtmlMode ? "<br>": "\n");
				if (  !(elmt is TextField) && elmt is Object && nLevel < nLevelRestrict ) {
					msg += viewThru( elmt, bBrief, nLevel + 1, nLevelRestrict );
				}
			}

			if (nLevel == 1) {
				msg += "┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷";
			}
			return bHasProps ? msg : "";
		}
		
		/// just for viewThru
		private static function getIndent(nLevel:Number):String {
			var prefix:String = "";
			for (var i:Number = nLevel; i>1; --i) {prefix += " │";}
			return prefix+" ├";
		}
		
	}

}